import random

print("这是一个猜拳游戏。")

choices = ['剪刀', '石头', '布']
flag = True
usercount = 0
computercount = 0
fla = '0'
while flag == True:
    user = input("剪刀、石头、布？ ")

    while user not in choices:
        print("请输入：剪刀、石头或布")
        user = input("剪刀、石头、布？ ")

    computer = random.choice(choices)

    if user == computer:
        print("平局！")
    elif (user == '剪刀' and computer == '布') or \
            (user == '石头' and computer == '剪刀') or \
            (user == '布' and computer == '石头'):
        print("恭喜，你赢了！")
        usercount += 1
    else:
        print("很遗憾，你输了！")
        computercount += 1
    choices2 = ['yes', 'no']
    if usercount == 3:
        print("游戏结束，你赢了")
        fla = input("是否要再玩一次？（yes/no）:")
        while fla not in ['yes', 'no']:  # 只能输入yes或no
            print("请输入：yes or no")
            fla = input("是否要再玩一次？（yes/no）:")
        if fla == 'yes':
            usercount = 0
            computercount = 0
        elif fla == 'no':
            flag = False
    elif computercount == 3:
        print("游戏结束，你输了")
        fla = input("是否要再玩一次？（yes/no）:")
        while fla not in ['yes', 'no']:   # 只能输入yes或no
            print("请输入：'yes' or 'no'")
            fla = input("是否要再玩一次？（yes/no）:")
        if fla == 'yes':
            usercount = 0
            computercount = 0
        elif fla == 'no':
            flag = False

print("谢谢游玩！")
